package com.chb.utils;

import com.chb.model.vo.PageBean;
import com.chb.model.vo.Result;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.util.List;

/**
 * @author: 陈海彬
 * @date: Created in 2023/10/1 19:08
 * @description: 分页工具
 * @modified By:
 * @version: 1.0
 */
public class PagingUtil<T> {

    /**
     * @param page     当前的页数
     * @param pageSize 每页展示的条目
     * @param list     要分页的数据
     * @return com.chb.model.vo.Result
     * @create by: 陈海彬
     * @description: 进行分页
     * @create time: 2023/10/1 19:11
     */
    public  Result paging(Integer page, Integer pageSize, List<T> list) {
        //进行分页
        PageHelper.startPage(page, pageSize);
        //返回分页的结果
        PageInfo<T> pageInfo = new PageInfo<>(list);
        PageBean<T> pageBean = new PageBean<>(pageInfo.getTotal(), pageInfo.getList());
        return Result.success(pageBean);
    }
}